using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Interactor_ColorWall : Unit_Interactor_Ctrl
{
    public GameManager.ColorType colorType;

    public List<Unit_Charactor_Ctrl> innerCharactors = new List<Unit_Charactor_Ctrl>();
    private Dictionary<Unit_Charactor_Ctrl, float> innerCharactorTime_Dictionary=new Dictionary<Unit_Charactor_Ctrl, float>();
    // Start is called before the first frame update
    void Start()
    {
        switch (colorType)
        {
            case GameManager.ColorType.None:
                break;
            default:
                renderer.material = GameManager.instance.gameColorMaterial_Group[colorType];
                break;
        }

    }

    // Update is called once per frame
    void Update()
    {
        foreach (Unit_Charactor_Ctrl charactor_Ctrl in innerCharactors)
        {
            innerCharactorTime_Dictionary[charactor_Ctrl] += Time.deltaTime;
            if (innerCharactorTime_Dictionary[charactor_Ctrl] >= 2)
            {
                if (charactor_Ctrl.colorType != colorType)
                {
                    charactor_Ctrl.SetColorPerformance(colorType);
                }
            }
        }
    }
    public override void ReceiveLight(Vector3 sourcePos, Vector3 sourceDirection)
    {
        base.receiveLightEvent?.Invoke(sourcePos, sourceDirection);
    }
    protected override void OnUnitTriggerEnter(Unit_Base unit_Base)
    {
        base.OnUnitTriggerEnter(unit_Base);
        switch (unit_Base.unitType)
        {
            case UnitType.Charactor:
                Unit_Charactor_Ctrl unit_Charactor_Ctrl = (Unit_Charactor_Ctrl)unit_Base;
                if (!innerCharactorTime_Dictionary.ContainsKey(unit_Charactor_Ctrl))
                {
                    innerCharactors.Add(unit_Charactor_Ctrl);
                    innerCharactorTime_Dictionary.TryAdd(unit_Charactor_Ctrl, 0);
                }
                break;
        }
    }
    protected override void OnUnitTriggerExit(Unit_Base unit_Base)
    {
        base.OnUnitTriggerExit(unit_Base);
        switch (unit_Base.unitType)
        {
            case UnitType.Charactor:
                Unit_Charactor_Ctrl unit_Charactor_Ctrl = (Unit_Charactor_Ctrl)unit_Base;
                if (innerCharactorTime_Dictionary.ContainsKey(unit_Charactor_Ctrl))
                {
                    innerCharactors.Remove(unit_Charactor_Ctrl);
                    innerCharactorTime_Dictionary.Remove(unit_Charactor_Ctrl);
                }
                break;
        }
    }
}
